package com.ruoyi.textbooks.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.textbooks.domain.JwTextbooks;
import com.ruoyi.textbooks.service.IJwTextbooksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 *  教材出版情况Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/textbooks/textbooks")
public class JwTextbooksController extends BaseController
{
    @Autowired
    private IJwTextbooksService jwTextbooksService;

    /**
     * 查询 教材出版情况列表
     */
    @PreAuthorize("@ss.hasPermi('textbooks:textbooks:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwTextbooks jwTextbooks)
    {
        startPage();
        List<JwTextbooks> list = jwTextbooksService.selectJwTextbooksList(jwTextbooks);
        return getDataTable(list);
    }

    /**
     * 导出 教材出版情况列表
     */
    @PreAuthorize("@ss.hasPermi('textbooks:textbooks:export')")
    @Log(title = " 教材出版情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwTextbooks jwTextbooks)
    {
        List<JwTextbooks> list = jwTextbooksService.selectJwTextbooksList(jwTextbooks);
        ExcelUtil<JwTextbooks> util = new ExcelUtil<JwTextbooks>(JwTextbooks.class);
        util.exportExcel(response, list, " 教材出版情况数据");
    }

    /**
     * 获取 教材出版情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('textbooks:textbooks:query')")
    @GetMapping(value = "/{textbookId}")
    public AjaxResult getInfo(@PathVariable("textbookId") Long textbookId)
    {
        return success(jwTextbooksService.selectJwTextbooksByTextbookId(textbookId));
    }

    /**
     * 新增 教材出版情况
     */
    @PreAuthorize("@ss.hasPermi('textbooks:textbooks:add')")
    @Log(title = " 教材出版情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwTextbooks jwTextbooks)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwTextbooks.setDeptId(104L);
        jwTextbooks.setUserId(user.getUserId());
        return toAjax(jwTextbooksService.insertJwTextbooks(jwTextbooks));
    }

    /**
     * 修改 教材出版情况
     */
    @PreAuthorize("@ss.hasPermi('textbooks:textbooks:edit')")
    @Log(title = " 教材出版情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwTextbooks jwTextbooks)
    {
        return toAjax(jwTextbooksService.updateJwTextbooks(jwTextbooks));
    }

    /**
     * 删除 教材出版情况
     */
    @PreAuthorize("@ss.hasPermi('textbooks:textbooks:remove')")
    @Log(title = " 教材出版情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{textbookIds}")
    public AjaxResult remove(@PathVariable Long[] textbookIds)
    {
        return toAjax(jwTextbooksService.deleteJwTextbooksByTextbookIds(textbookIds));
    }
}
